import React, { Component } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as contentActions from './store/actions/contentActions'

class App extends Component {

  constructor () {
    super()
    this.that = this
    this.myRef = React.createRef()
    this.myRef1 = React.createRef()
  }

  state = {
    addContent: ''
  }

  handle = (e) => {
    this.setState({
      [e.target.name]: e.target.value
    })
  }

  handleClick = () => {
    const content = this.myRef.current.value
    const content1 = this.myRef1.current.value
    console.log(content1, content, '===========')
    this.props.addContent(this.state.addContent)
    this.setState({
      addContent: ''
    })
  }

  render() {
    console.log(this.props)
    let contetnList = this.props.content
    return (
      <div className="App">
        <input name='addContent' value={this.state.addContent} ref={this.myRef} onChange={ this.handle } />
        <input ref={this.myRef1}  />
        <button onClick={ this.handleClick }>添加</button>
        <ul>
          {
            contetnList.map((con, index) => <li key={index}>{con}</li>)
          }
        </ul>
      </div>
    );
  }
}

const mapStoreTOProps = (state) => {
  return {
    content: state.content.content
  }
}

const mapDispatchToProps = (dispatch) => ({
  ...bindActionCreators(contentActions, dispatch)
})

export default connect(mapStoreTOProps, mapDispatchToProps)(App);
